package servlets;

import java.io.IOException;
import java.io.OutputStream;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;

import controle.RetornaItensBD;


/**
 * Servlet implementation class Grafico
 */
@WebServlet("/Grafico")
public class Grafico extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
 
    public Grafico() {
        super();
    }

	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		response.setContentType("image/png");
		
		OutputStream out = response.getOutputStream();
		
		
		JFreeChart grafico = ChartFactory.createLineChart("Meu Grafico", "Hora", "Valor", RetornaItensBD.retornaSet(), PlotOrientation.VERTICAL, false,false,false);
		
		ChartUtilities.writeChartAsPNG(out, grafico, 400, 250);
	}	

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	
		
	}

}
